<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 8/8/14
 * Time: 3:46 PM
 */

namespace UploadFile\Service;
use UploadFile\Mapper\UploadFileInterface;

class UploadFile
{

    protected $uploadFileMapper;

    public function createUploadFileUser($user)
    {
        /*--------------------------Upload_File------------------------------------------*/
        $userAvatar = $user->getAvatar();
        $userAvatarPath = $userAvatar->getImagePath();
        list($a , $b , $c , $imagePath) = explode('/' , $userAvatarPath['tmp_name']);
        $userAvatar->setImagePath($imagePath);

        $this->getUploadFileMapper()->insert($userAvatar);
        /*--------------------------------------------------------------------*/

        /*--------------------------Upload_File_Linker------------------------------------------*/
        $userAvatarLinker = new \UploadFile\Entity\ImageLinker();
        $userAvatarLinker->setImageId($userAvatar->getImageId());
        $userAvatarLinker->setDetailedId($userAvatar->getImageId());
        $userAvatarLinker->setObjectId($user->getUserId());
        $userAvatarLinker->setObjectType('user_avatar');
        $userAvatarLinker->setStatus('A');
        $userAvatarLinker->setPosition(0);
        $userAvatarLinker->setType('M');
        $this->getUploadFileLinkerMapper()->insert($userAvatarLinker);
        /*--------------------------------------------------------------------*/
    }

    public function setUploadFileMapper(UploadFileInterface $uploadFileMapper)
    {
        $this->uploadFileMapper = $uploadFileMapper;
        return $this;
    }

    public function getUploadFileMapper()
    {
        if (null === $this->uploadFileMapper) {
            $this->uploadFileMapper = $this->serviceManager->get('upload_file_mapper');
        }
        return $this->uploadFileMapper;

    }

    public function setUploadFileLinkerMapper(UploadFileInterface $uploadFileMapper)
    {
        $this->uploadFileMapper = $uploadFileMapper;
        return $this;
    }

    public function getUploadFileLinkerMapper()
    {
        if (null === $this->uploadFileMapper) {
            $this->uploadFileMapper = $this->serviceManager->get('upload_file_linker_mapper');
        }
        return $this->uploadFileMapper;

    }
} 